﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AxSHDocVw;
using System.Windows.Forms;

namespace Insurance_Quotation_App
{
    class TokioMarine
    {
        private static AxWebBrowser axWebBrowser = null;

        public static void Run(AxWebBrowser browser)
        {
            TokioMarine.axWebBrowser = browser;

            axWebBrowser.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(axWebBrowser_DocumentComplete);
            axWebBrowser.Navigate("https://connect.tokiomarine.com.sg/Intermediaries/security/IntermediaryLogin.aspx");
        }

        private static void axWebBrowser_DocumentComplete(object sender, DWebBrowserEvents2_DocumentCompleteEvent e)
        {
            axWebBrowser.DocumentComplete -= axWebBrowser_DocumentComplete;
            Autofill.SetText(axWebBrowser, "name", "ctl00$eTranContentPlaceHolder01$Login$UserIDText", "1407DDA");
            Autofill.SetText(axWebBrowser, "name", "ctl00$eTranContentPlaceHolder01$Login$PasswordText", "samshawn");
            axWebBrowser.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(axWebBrowser_DocumentComplete2);
            Autofill.ClickButton(axWebBrowser, "name", "ctl00$eTranContentPlaceHolder01$Login$LoginButton", "input");
        }
           
        private static void axWebBrowser_DocumentComplete2(object sender, DWebBrowserEvents2_DocumentCompleteEvent e)
        {
            axWebBrowser.DocumentComplete -= axWebBrowser_DocumentComplete2;
            axWebBrowser.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(axWebBrowser_DocumentComplete3);
            Autofill.ClickButton(axWebBrowser, "id", "ctl00_eTranContentPlaceHolder01_HyperLink3", "a");
        }

        private static void axWebBrowser_DocumentComplete3(object sender, DWebBrowserEvents2_DocumentCompleteEvent e)
        {
            axWebBrowser.DocumentComplete -= axWebBrowser_DocumentComplete3;
            
            axWebBrowser.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(axWebBrowser_DocumentComplete4);
            Autofill.ClickButton(axWebBrowser, "name", "ctl00$eTranContentPlaceHolder01$CreateButton", "input");            
        }

        private static void axWebBrowser_DocumentComplete4(object sender, DWebBrowserEvents2_DocumentCompleteEvent e)
        {
            Autofill.SetSelectList(axWebBrowser, "name", "ctl00$eTranContentPlaceHolder02$TX020001", "CO");
            axWebBrowser.DocumentComplete -= axWebBrowser_DocumentComplete4;
            Autofill.SetRadio(axWebBrowser, "name", "ctl00$eTranContentPlaceHolder02$TX020002", "False");
            Autofill.SetSelectList(axWebBrowser, "name", "ctl00$eTranContentPlaceHolder02$TX020102", "MR");
            Autofill.SetText(axWebBrowser, "name", "ctl00$eTranContentPlaceHolder02$TX020103", Common.name);
            Autofill.SetText(axWebBrowser, "name", "ctl00$eTranContentPlaceHolder02$TX020105", Common.NRIC);
            Autofill.SetText(axWebBrowser, "name", "ctl00$eTranContentPlaceHolder02$TX020107", Common.dobDay + "/" + Common.dobMonth + "/" + Common.dobYear);
            Autofill.SetSelectList(axWebBrowser, "name", "ctl00$eTranContentPlaceHolder02$TX020109", "M");
            Autofill.SetSelectList(axWebBrowser, "name", "ctl00$eTranContentPlaceHolder02$TX020118", "M");
            Autofill.SetSelectList(axWebBrowser, "name", "ctl00$eTranContentPlaceHolder02$TX020106", "SGP");
            Autofill.SetSelectList(axWebBrowser, "name", "ctl00$eTranContentPlaceHolder02$TX020108", "M023");
            Autofill.SetText(axWebBrowser, "name", "ctl00$eTranContentPlaceHolder02$TX020110", Common.mobile);
            Autofill.SetText(axWebBrowser, "name", "ctl00$eTranContentPlaceHolder02$TX020137", Common.licDay + "/" + Common.licMonth + "/" + Common.licYear);
            Autofill.SetRadio(axWebBrowser, "name", "ctl00$eTranContentPlaceHolder02$TX020119", "True");
            Autofill.SetText(axWebBrowser, "name", "ctl00$eTranContentPlaceHolder02$TX020133", Common.drivingExperience); SendKeys.Send("{ENTER}");
            Autofill.SetSelectList(axWebBrowser, "name", "ctl00$eTranContentPlaceHolder02$TX020116", "0");
            Autofill.SetSelectList(axWebBrowser, "name", "ctl00$eTranContentPlaceHolder02$TX020117", "50");
            
            axWebBrowser.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(axWebBrowser_DocumentComplete5);
        }
        private static void axWebBrowser_DocumentComplete5(object sender, DWebBrowserEvents2_DocumentCompleteEvent e)
        {
            axWebBrowser.DocumentComplete -= axWebBrowser_DocumentComplete5;
            
            axWebBrowser.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(axWebBrowser_DocumentComplete6);
        }
        private static void axWebBrowser_DocumentComplete6(object sender, DWebBrowserEvents2_DocumentCompleteEvent e)
        {
            axWebBrowser.DocumentComplete -= axWebBrowser_DocumentComplete6;

            axWebBrowser.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(axWebBrowser_DocumentComplete7);
        }
        private static void axWebBrowser_DocumentComplete7(object sender, DWebBrowserEvents2_DocumentCompleteEvent e)
        {
            axWebBrowser.DocumentComplete -= axWebBrowser_DocumentComplete7;

            axWebBrowser.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(axWebBrowser_DocumentComplete8);
        }
        private static void axWebBrowser_DocumentComplete8(object sender, DWebBrowserEvents2_DocumentCompleteEvent e)
        {
            axWebBrowser.DocumentComplete -= axWebBrowser_DocumentComplete8;
            Autofill.SetSelectList(axWebBrowser, "name", "ctl00$eTranContentPlaceHolder02$TX020201", "TOY");
            axWebBrowser.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(axWebBrowser_DocumentComplete9);
        }
        private static void axWebBrowser_DocumentComplete9(object sender, DWebBrowserEvents2_DocumentCompleteEvent e)
        {
            axWebBrowser.DocumentComplete -= axWebBrowser_DocumentComplete9;
            Autofill.SetSelectList(axWebBrowser, "name", "ctl00$eTranContentPlaceHolder02$TX020202", "TOYP2023");
            axWebBrowser.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(axWebBrowser_DocumentComplete10);
        }
        private static void axWebBrowser_DocumentComplete10(object sender, DWebBrowserEvents2_DocumentCompleteEvent e)
        {
            axWebBrowser.DocumentComplete -= axWebBrowser_DocumentComplete10;
            Autofill.SetSelectList(axWebBrowser, "name", "ctl00$eTranContentPlaceHolder02$TX020205", "PU");
            axWebBrowser.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(axWebBrowser_DocumentComplete11);
        }

        private static void axWebBrowser_DocumentComplete11(object sender, DWebBrowserEvents2_DocumentCompleteEvent e)
        {
            axWebBrowser.DocumentComplete -= axWebBrowser_DocumentComplete11;
            Autofill.SetSelectList(axWebBrowser, "name", "ctl00$eTranContentPlaceHolder02$TX020206", "2006");
            Autofill.SetSelectList(axWebBrowser, "name", "ctl00$eTranContentPlaceHolder02$TX020206", "2006");
            Autofill.SetSelectList(axWebBrowser, "name", "ctl00$eTranContentPlaceHolder02$TX020208", "2006");
            Autofill.SetRadio(axWebBrowser, "name", "ctl00$eTranContentPlaceHolder02$TX020215", "False");
            Autofill.ClickButton(axWebBrowser, "name", "ctl00$eTranContentPlaceHolder02$TX020215", "input");
        }
    }
}
